<html>
<head>
    <title>Testing vibrate 3 times in an iframe</title>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <script src="/js-test-resources/user-gesture-utils.js"></script>
    <script>
        function loaded()
        {
            document.getElementsByTagName('h4')[0].innerHTML = document.domain;
        }

        function startTest(event)
        {
            // A manual click should enable vibrate.
            if (window.eventSender) {
                test(function() {
                  assert_false(
                      navigator.vibrate(200),
                      "1. Blocked vibrate before user gesture.");
                });
                var element = document.getElementById("b");
                simulateUserClick(element.offsetLeft + event.data.x + 2, element.offsetTop + event.data.y + 2);
            }
        }

        function performTestAfterClick()
        {
           test(function () {
             assert_true(
                 navigator.vibrate(200),
                 "3. Vibrate after user gesture succeeded.");
           });
        }

        function performTestWithClick()
        {
          test(function () {
            assert_true(
                navigator.vibrate(200),
                "2. Vibrate triggered by user gesture succeeded.");
          });
          window.requestAnimationFrame(performTestAfterClick);
        }

        window.addEventListener("message", startTest, false);
    </script>
</head>
<body onload="loaded();">
    <h4>DOMAIN</h4>
    <button id="b" onclick="performTestWithClick();">Perform Test</button>
</body>
</html>

